package demo1;

public class StringDemo4  {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,9};
       String str =  arrayToString(arr);
        System.out.println(str);
    }
    public static String arrayToString(int[] arr) {
        if(arr==null){
            return "";
        }
        if(arr.length==0){
            return "[]";
        }
        String result="[";
        for (int i = 0; i < arr.length; i++) {
            if(i==arr.length-1){
                result += arr[i];
            }else {
                result += arr[i] + ",";
            }
        }
        result += "]";
        return result;
    }
}
